//
//  SLHomeBannerView.m
//  SoccerLottery
//
//  Created by chuanshuangzhang chuan shuang on 15/12/24.
//  Copyright © 2015年 chuanshuangzhang. All rights reserved.
//

#import "SLHomeBannerView.h"

@implementation SLHomeBannerView


- (id)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame]){
        
        CGFloat width = frame.size.width/3.0;
        
        UIButton *registerButton = [[UIButton alloc]init];
        registerButton.frame = CGRectMake(0, 0, width, frame.size.height);
        [registerButton setTitle:@"会员注册" forState:UIControlStateNormal];
        [self setLayout:registerButton image:@"register"];
        [registerButton addTarget:self action:@selector(openRegister:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:registerButton];
        
        UIButton *loginButton = [[UIButton alloc]init];
        loginButton.frame = CGRectMake(registerButton.right, 0, width, frame.size.height);
        [loginButton setTitle:@"会员登录" forState:UIControlStateNormal];
        [self setLayout:loginButton image:@"login"];
        [loginButton addTarget:self action:@selector(openLogin:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:loginButton];
    }
    return self;
}

- (void)setLayout:(UIButton *)btn image:(NSString *)imageName
{
    UIFont *font;
    if(App_Frame_Height <=568){
        font = [UIFont fontWithName:@"Arial" size:12];
    }else {
        font = [UIFont fontWithName:@"Arial" size:15];
    }
    UIImage *image = [UIImage imageNamed:imageName];
    [btn.titleLabel setFont:font];
    [btn setImage:image forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"select_%@",imageName]] forState:UIControlStateHighlighted];
    [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"select_%@",imageName]] forState:UIControlStateSelected];
    [btn setTitleColor:RGBACOLOR(135, 135, 135, 1.0) forState:UIControlStateNormal];
    [btn setTitleColor:RGBACOLOR(255, 255, 255, 1.0) forState:UIControlStateSelected];
    [btn setTitleColor:RGBACOLOR(255, 255, 255, 1.0) forState:UIControlStateHighlighted];
    [btn setTitleEdgeInsets:UIEdgeInsetsMake(55,-image.size.width, 0, 0)];
    CGSize titleSize = [btn.titleLabel.text boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil].size;
    [btn.imageView setContentMode:UIViewContentModeCenter];
    [btn setImageEdgeInsets:UIEdgeInsetsMake(-15.0,0.0,0.0,-titleSize.width)];
    [btn setTitleEdgeInsets:UIEdgeInsetsMake(32.0,-image.size.width,0.0,0.0)];
}
- (IBAction)openLogin:(id)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(bannerViewDidSelectLogin:)]) {
        [self.delegate bannerViewDidSelectLogin:self];
    }
}

- (IBAction)openRegister:(id)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(bannerViewDidSelectRegister:)]) {
        [self.delegate bannerViewDidSelectRegister:self];
    }
}

@end
